package com.noreply.springlearning.imports;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.MultiValueMap;

/**
 * @author noreply
 * @description
 * @datetime 2022/5/6 10:13
 */
public class UserServiceBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {


    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
        // annotationMetadata里面可以获取到UserRegisterConfig上面的注解
        BeanDefinitionBuilder userService = BeanDefinitionBuilder.rootBeanDefinition(UserService.class);
        //通过registry就可以注入到容器里啦
        beanDefinitionRegistry.registerBeanDefinition("userService", userService.getBeanDefinition());
    }
}
